$(document).ready(function() {
	logincheck()
})

function logincheck() {
	$.ajax({
		type: "post",
		url: "/eduser/api/logincheck",
		dataType:"text",
		jsonp: "callback",
		jsonpCallback: "callback",
		success: function(json) {
			if(json.flag) {
				getcourser();
			} else {
				$("#tishi").show();
				gocheck();
			}
		},
		error: function(json) {
			console.log(json);
		}

	});
}

function gocheck() {
	var urldata = escape("http://39.105.36.71");
	window.location.href = "https://workflow.sinooceangroup.com/THRWebApp/passport.htm?client_id=ghyydjt&redirect_uri=http%3A%2F%2Fyuanyang.haoxuehaozhi.com%2Feduser%2Fapi%2Foauth%2Fyuanyangcallback%3Freturnurl%3D' + urldata + '&response_type=code#/oauth-authorize'"
	//window.location.href="https://www.baidu.com/"
}

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for(var i = 0; i < vars.length; i++) {
		var pair = vars[i].split("=");
		if(pair[0] == variable) {
			return pair[1];
		}
	}
	return(false);
}

function userlogin(name_s, password_s) {
	$.ajax({
		type: "post",
		url: "/eduser/api/login",
		dataType: "text",
		jsonp: "callback",
		jsonpCallback: "callback",
		data: {
			'name': name_s,
			'password': password_s
		},
		success: function(json) {
			console.log(json);
			var map = eval('(' + json + ')');
			addCookie('uid', map.token);
		},
		error: function(json) {
			console.log(json);
		}

	});
}

function getCookie(name) {
	var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");

	if(arr = document.cookie.match(reg))

		return unescape(arr[2]);
	else
		return null;
}

function addCookie(objName, objValue, objHours) {
	var str = objName + "=" + escape(objValue); //编码
	if(objHours > 0) { //为0时不设定过期时间，浏览器关闭时cookie自动消失
		var date = new Date();
		var ms = objHours * 3600 * 1000;
		date.setTime(date.getTime() + ms);
		str += "; expires=" + date.toGMTString();
	}
	document.cookie = str;

	getcourser();
}

function getcourser() {
	$.ajax({
		type: "get",
		url: "/eduser/api/courselesson/getPlayAddress/382/753",
		dataType: "text",
		jsonp: "callback",
		jsonpCallback: "callback",
		success: function(json) {
			var map = eval('(' + json + ')');
			console.log(map.info.media[0].src)
			src_s = map.info.media[0].src;
			myPlayer = videojs('my-video', option, function onPlayerReady() {
				var myPlayer = this;
				myPlayer.src({
					src: src_s,
					type: "application/x-mpegURL"
				});
				videojs.log("播放器已经准备好了!");
				this.play();
			});
		},
		error: function(json) {
			console.log(json);
		}

	});
}